package model

import java.io.File
import java.util.concurrent.CopyOnWriteArrayList

/**
 * 地图类
 * 0:空 1:Wall 2:Steel 3:Water 4:Grass 5:Enemy 6:SmallWall 7:Camp
 */
class Map{
    var list=CopyOnWriteArrayList<IView>()
    var enemyCount=20
    val enemyActiveCount=3
    var index=0
    val enemyLocation= ArrayList<Pair<Int,Int>>()
    constructor(name: String){
        var file=File(javaClass.getResource("/map/1.map").path)
        for ((i,row) in file.readLines().withIndex()){
            for ((j,value) in row.withIndex()){
                when(value){
                    '0' -> 0
                    '1' -> list.add(Wall(i,j))
                    '2' -> list.add(Steel(i,j))
                    '3' -> list.add(Water(i,j))
                    '4' -> list.add(Grass(i,j))
                    '5' -> enemyLocation.add(Pair(i,j))
                    '6' -> {
                        var wall=Wall(i,j)
                        wall.blood=6
                        list.add(wall)
                    }
                    '7' -> list.add(Camp())
                    else -> throw Exception("$value 不能被解析")
                }
            }
        }
    }

}